/**
 * 请求控制器处理
 * @author yangjian102621@163.com
 */

"use strict"

module.exports = {


	// index page
	index : function(req, res) {

		var params = req.getParameters();
		var data = {
			title : "测试页面",
			hello : "Welcome, this is the index page",
			params : params
		};
		
		var app = req.getApp();
		var db = app.getDB();

		db.query("select * from user", function(err, rows) {
		
			if ( err ) {
				console.log(err);
			} else {
				data.user = rows;
			}

			res.display("index", data);
		});


	},


	// login page
	login : function(req, res) {

		res.writeHead(200, {"Content-Type" : "text/html"});
		res.write("<h1>This is the login page.</h1>");

		var body = '<html>'+
			'<head>'+
			'<meta http-equiv="Content-Type" content="text/html; '+
			'charset=UTF-8" />'+
			'</head>'+
			'<body>'+
			'<form action="/user/loginCheck" method="post">'+
			'<input type="text" name="data[username]" value="xiaoyang333" />'+
			'<input type="text" name="data[password]" value="123456" />'+
			'<input type="file" name="src"  />'+
			'<input type="submit" value="立即登陆" />'+
			'</form>'+
			'</body>'+
			'</html>';

		res.write(body);
		res.end();
	},


	//register page
	register : function(req, res) {

		res.write("<h1>This is the register page.</h1>");
		res.end();

	},

	//login check page
	loginCheck : function(req, res) {

		res.write("<h1>登陆验证页面.</h1>");
		res.write("<h2>接收到的POST参数：</h2>");
		var data = req.getPostDataArray("data");
		for ( var name in data ) {
			res.write("<h3>"+name+" : "+data[name]+"</h3>");
		}

		res.end();
	}
}
